/*set working directory*/

****************************************************************************************
*Figure 1: The Distribution of Democracy Scores by Rater Nationality
****************************************************************************************
use "uganda_expert_data.dta", clear

twoway (histogram ugtotraw if ug_nat==1 & ugandaspeaker=="Yes", width(10)  color(grey%40) ) ///
                 (histogram ugtotraw if ug_nat==0 & ugandaspeaker=="Yes", width(10)  lcolor(black) color(blue%20)   ), graphregion(color(white)) ///
				 xtitle("Freedom House Score") ///
				 xline(37.85, lcolor(blue)) ///
				 xline(48.36, lcolor(grey)) ///
               legend(order(1 "Ugandan" 2 "Non-Ugandan"))
/*add text manually*/
graph export "Figures/ugtotraw_hist.png", as(png) replace
 

****************************************************************************************	
*Figure 2: The Relationship between Rater Nationality and Democracy Assessments
****************************************************************************************	
use "uganda_expert_data.dta", clear

eststo clear
display "without covariates"
reg ugpr_std ug_nat if ugandaspeaker=="Yes", vce(robust)
eststo ugpr
reg ugcl_std ug_nat if ugandaspeaker=="Yes", vce(robust)
eststo ugcl
reg ugtotraw_std ug_nat  if ugandaspeaker=="Yes", vce(robust)
eststo ugtot

display "with covariates"
reg ugpr_std ug_nat female leftright ugknowledge ugcert ugsources i.job if ugandaspeaker=="Yes", vce(robust)
eststo ugpr1
reg ugcl_std ug_nat female leftright ugknowledge ugcert ugsources i.job if  ugandaspeaker=="Yes", vce(robust)
eststo ugcl1
reg ugtotraw_std ug_nat female leftright ugknowledge ugcert ugsources i.job if ugandaspeaker=="Yes", vce(robust)
eststo ugtot1

# delimit;	 
	coefplot 
	  (ugpr, msymbol(circle)) (ugpr1, msymbol(diamond)) ||
	  ugcl ugcl1 ||
	  ugtot ugtot1,
	keep(ug_nat) bycoefs bylabels ("Political Rights" "Civil Liberties" "Total") 
	 xline(0, lcolor(gray)) graphregion(margin(l=1) color(white)) 
	 scheme(stcolor) levels(95 90)
	 xtitle(Coefficient for National Raters, size(med)) ylabel(,labsize(med)) xlabel(,labsize(med) format(%03.1f))
	 legend(order(3 "No covariates" 6 "Covariates") size(med));
graph export "Figures/ugnat_ratings.png", as(png) replace

************************************************************************************************
*Table 1: The Relationship between Democracy Scores and Rater Nationality and Residence
************************************************************************************************
use "V-Dem-CY-Full+Others-v11.1.dta", clear
keep country_name country_text_id country_id year e_polity2 e_migdppcln e_migdppc
keep if year==2012
tempfile temp
save `temp'

clear
import delimited "Restricted/psq.csv", encoding(ISO-8859-2) /*this dataset is proprietary*/
reshape wide value, i(coder_id) j(name) string
sort coder_id
tempfile psq
save `psq'

clear
import delimited "Restricted/v2zzdemyc.csv", encoding(ISO-8859-2) clear /*this dataset is proprietary*/
merge 1:1 coder_id using `psq'
tab _merge
drop _merge
tempfile merged
save `merged'

clear
import delimited "coder_level_ds_v11.1.csv", encoding(ISO-8859-2)  
keep country_text_id coder_id historical_date country_id v2elfrfair v2jupoatck ///
v2lgoppart v2psbars v2exrescon v2eldonate v2elpubfin v2elembaut v2elembcap v2elmulpar ///
v2elrgstry v2elvotbuy v2elirreg v2elintim v2elpeace v2elboycot v2elfrcamp v2elpdcamp ///
v2elpaidig v2elfrfair v2elaccept v2elasmoff v2elrgpwr v2ellocpwr ///
v2elffelr v2elffelrbin v2elsnlsff v2psbars v2psparban v2psoppaut v2psorgs v2psprbrch ///
v2psprlnks v2psplats v2pscnslnl v2pscohesv v2pscomprg v2psnatpar v2pssunpar v2exrescon ///
v2exbribe v2exembez v2excrptps v2exthftps v2exremhsp v2exdfdshs v2exdfcbhs v2exdfcbhs_rec ///
v2exdfvths v2exdfdmhs v2exdfpphs v2exremhog v2exdjdshg v2exdjcbhg v2exdfdshg v2exdfvthg ///
v2exdfpphg v2regsupgroupssize v2regoppgroupssize v2lgdomchm v2lgqstexp ///
v2lginvstp v2lgotovst v2lgcrrpt v2lgoppart v2lgfunds v2lgdsadlo v2lgdsadlobin ///
v2lglegpup v2lglegplo v2lgcomslo v2lgsrvlo v2lgstafflo v2dlreason v2dlcommon v2dlcountr ///
v2dlconslt v2dlengage v2dlencmps v2dlunivl v2jureform v2jupurge v2jupoatck v2jupack ///
v2juaccnt v2jucorrdc v2juhcind v2juncind v2juhccomp v2jucomp v2jureview v2cltort ///
v2clkill v2clslavem v2clslavef v2cltrnslw v2clrspct v2clacjstm v2clacjstw v2clacjust ///
v2clsocgrp v2clrgunev v2cldiscm v2cldiscw v2clacfree v2clrelig v2clfmove v2cldmovem ///
v2cldmovew v2clstown v2clprptym v2clprptyw v2svdomaut v2svinlaut v2cseeorgs v2csreprss ///
v2cscnsult v2csprtcpt v2csgender v2csantimv v2csrlgrep v2csrlgcon v2mecenefm v2mecenefi ///
v2mecenefibin v2mecrit v2merange v2meharjrn v2meslfcen v2mebias v2mecorrpt ///
v2pepwrses v2pepwrsoc v2pepwrgen v2pepwrort v2peedueq v2pehealth v2peapsecon v2peasjsoecon ///
v2peasbecon v2clgencl v2peapsgen v2peasjgen v2peasbgen v2pepwrgeo v2clgeocl v2peapsgeo ///
v2peasjgeo v2peasbegeo v2clpolcl v2peapspol v2peasjpol v2peasbepol v2peapssoc v2peasjsoc ///
v2peasbsoc v2exl_legitideol v2exl_legitlead v2exl_legitperf ///
v2exl_legitratio v2cacamps v2caviol v2caassemb ///
v2cagenmob v2caconmob v2cademmob v2caautmob v2castate v2catrauni v2capolit v2canonpol ///
v2cafres v2cafexch v2cainsaut v2casurv v2cacritic v2zz*

by coder_id country_id, sort: gen nvals = _n == 1
by coder_id, sort: replace nvals = sum(nvals)
by coder_id, sort: gen nvalsmax = nvals[_N] 
tab nvalsmax
keep if nvalsmax==1
isid coder_id country_id historical_date

gen singlecountrycoder = 1
egen byte coder_tag = tag(coder_id)
keep if coder_tag==1
keep coder_id singlecountrycoder 
tempfile singlecountrycoderids
save `singlecountrycoderids'

use `merged', clear
sort coder_id
merge 1:1 coder_id using `singlecountrycoderids'
keep if _merge==3
drop _merge

replace country_id = 110 if country_id==213
replace country_name = "China" if country_name=="CHINA"

merge m:1 country_id using "vdem_country_codes_regions.dta"
keep if _merge==3
drop _merge

merge m:1 country_name using `temp'

gen bornin=0 if valuev2zzbornin=="FALSE"
replace bornin=1 if valuev2zzbornin=="TRUE"

gen reside=0 if valuev2zzreside=="FALSE"
replace reside=1 if valuev2zzreside=="TRUE"

encode region, generate(region2)
bys country_id: egen byte coder_tot = count(country_id)

bys country_id: egen c = count(coder_id) if bornin==1
bys country_id: egen meanbornin = mean(bornin) 

egen byte country_tag = tag(country_name)

label variable meanbornin "% National Coders"
label variable bornin "Coder Nationality"

label define bornin 0 "Non-national" 1 "National"
label values bornin bornin

label define reside 0 "Non-resident" 1 "Resident"
label values reside reside

sort country_name coder_id
rename code v2zzdemyc

reg v2zzdemyc bornin, vce(robust)
eststo d1
estadd local fe1 "No"
estadd local fe2 "No"

reg v2zzdemyc reside, vce(robust)
eststo d2
estadd local fe1 "No"
estadd local fe2 "No"

reg v2zzdemyc bornin i.region2, vce(robust)
eststo d3
estadd local fe1 "Yes"
estadd local fe2 "No"

reg v2zzdemyc reside i.region2, vce(robust)
eststo d4
estadd local fe1 "Yes"
estadd local fe2 "No"

reg v2zzdemyc bornin i.country_id, vce(robust)
eststo d5
estadd local fe1 "No"
estadd local fe2 "Yes"

reg v2zzdemyc reside i.country_id, vce(robust)
eststo d6
estadd local fe1 "No"
estadd local fe2 "Yes"

# delimit;
		esttab    d1 d2 d3 d4 d5 d6
		using "Tables/bornin_reside_apr2024.tex",
				title(Coder nationality, residence and democracy scores in 2012)
				keep( bornin reside _cons)
				varlabels (
				bornin "Coder is a national"
				reside "Coder is a resident"
				_cons "Constant")
				cells(b(fmt(%5.3f) star) se(fmt(%5.3f) par))
				starlevels(* .10 ** .05 *** .01) 					
				mtitles( "\shortstack{National}"
				"\shortstack{Resident}"
				"\shortstack{National}"
						"\shortstack{Resident}"
						"\shortstack{National}"
						"\shortstack{Resident}")
				stats(N r2 fe1 fe2, labels("N" "R$^2$" "Region FE" "Country FE" fmt(%5)) 	
				fmt(0 3)) label fragment nonotes replace;

************************************************************************************************
*Table 2: The Relationship between V-Dem Indicators and Rater Nationality
************************************************************************************************
clear
import delimited "coder_level_ds_v11.1.csv", encoding(ISO-8859-2)  

keep country_text_id coder_id historical_date country_id v2elfrfair v2jupoatck ///
v2lgoppart v2psbars v2exrescon v2eldonate v2elpubfin v2elembaut v2elembcap v2elmulpar ///
v2elrgstry v2elvotbuy v2elirreg v2elintim v2elpeace v2elboycot v2elfrcamp v2elpdcamp ///
v2elpaidig v2elfrfair v2elaccept v2elasmoff v2elrgpwr v2ellocpwr ///
v2elffelr v2elffelrbin v2elsnlsff v2psbars v2psparban v2psoppaut v2psorgs v2psprbrch ///
v2psprlnks v2psplats v2pscnslnl v2pscohesv v2pscomprg v2psnatpar v2pssunpar v2exrescon ///
v2exbribe v2exembez v2excrptps v2exthftps v2exremhsp v2exdfdshs v2exdfcbhs v2exdfcbhs_rec ///
v2exdfvths v2exdfdmhs v2exdfpphs v2exremhog v2exdjdshg v2exdjcbhg v2exdfdshg v2exdfvthg ///
v2exdfpphg v2regsupgroupssize v2regoppgroupssize v2lgdomchm v2lgqstexp ///
v2lginvstp v2lgotovst v2lgcrrpt v2lgoppart v2lgfunds v2lgdsadlo v2lgdsadlobin ///
v2lglegpup v2lglegplo v2lgcomslo v2lgsrvlo v2lgstafflo v2dlreason v2dlcommon v2dlcountr ///
v2dlconslt v2dlengage v2dlencmps v2dlunivl v2jureform v2jupurge v2jupoatck v2jupack ///
v2juaccnt v2jucorrdc v2juhcind v2juncind v2juhccomp v2jucomp v2jureview v2cltort ///
v2clkill v2clslavem v2clslavef v2cltrnslw v2clrspct v2clacjstm v2clacjstw v2clacjust ///
v2clsocgrp v2clrgunev v2cldiscm v2cldiscw v2clacfree v2clrelig v2clfmove v2cldmovem ///
v2cldmovew v2clstown v2clprptym v2clprptyw v2svdomaut v2svinlaut v2cseeorgs v2csreprss ///
v2cscnsult v2csprtcpt v2csgender v2csantimv v2csrlgrep v2csrlgcon v2mecenefm v2mecenefi ///
v2mecenefibin v2mecrit v2merange v2meharjrn v2meslfcen v2mebias v2mecorrpt ///
v2pepwrses v2pepwrsoc v2pepwrgen v2pepwrort v2peedueq v2pehealth v2peapsecon v2peasjsoecon ///
v2peasbecon v2clgencl v2peapsgen v2peasjgen v2peasbgen v2pepwrgeo v2clgeocl v2peapsgeo ///
v2peasjgeo v2peasbegeo v2clpolcl v2peapspol v2peasjpol v2peasbepol v2peapssoc v2peasjsoc ///
v2peasbsoc v2exl_legitideol v2exl_legitlead v2exl_legitperf ///
v2exl_legitratio v2cacamps v2caviol v2caassemb ///
v2cagenmob v2caconmob v2cademmob v2caautmob v2castate v2catrauni v2capolit v2canonpol ///
v2cafres v2cafexch v2cainsaut v2casurv v2cacritic v2zz*

by coder_id country_id, sort: gen nvals = _n == 1
by coder_id, sort: replace nvals = sum(nvals)
by coder_id, sort: gen nvalsmax = nvals[_N] 
tab nvalsmax
keep if nvalsmax==1
isid coder_id country_id historical_date
tempfile subset
save `subset'

gen singlecountrycoder = 1
egen byte coder_tag = tag(coder_id)
keep if coder_tag==1
keep coder_id singlecountrycoder 
tempfile singlecountrycoderids
save `singlecountrycoderids'

use "V-Dem-CY-Full+Others-v11.1.dta", clear
keep country_name country_text_id country_id year e_polity2 e_migdppcln e_migdppc
keep if year==2012
tempfile temp
save `temp'

clear
import delimited "Restricted/psq.csv", encoding(ISO-8859-2)
reshape wide value, i(coder_id) j(name) string
sort coder_id
tempfile psq
save `psq'

clear
import delimited "Restricted/v2zzdemyc.csv", encoding(ISO-8859-2)  
merge 1:1 coder_id using `psq'
drop _merge

merge 1:1 coder_id using `singlecountrycoderids'
keep if _merge==3
drop _merge

replace country_id = 110 if country_id==213
replace country_name = "China" if country_name=="CHINA"

merge m:1 country_id using "vdem_country_codes_regions.dta"
keep if _merge==3
drop _merge

merge m:1 country_name using `temp'

gen bornin=0 if valuev2zzbornin=="FALSE"
replace bornin=1 if valuev2zzbornin=="TRUE"

gen reside=0 if valuev2zzreside=="FALSE"
replace reside=1 if valuev2zzreside=="TRUE"

encode region, generate(region2)
bys country_id: egen byte coder_tot = count(country_id)

bys country_id: egen c = count(coder_id) if bornin==1
by country_id, sort : egen float coderbornin = mode(c)
g meanbornin = (coderbornin/coder_tot)

egen byte country_tag = tag(country_name)

label variable meanbornin "% National Coders"
label variable bornin "Coder Nationality"

label define bornin 0 "Non-national" 1 "National"
label values bornin bornin

label define reside 0 "Non-resident" 1 "Resident"
label values reside reside

sort country_name coder_id
rename code v2zzdemyc

isid coder_id

merge 1:m coder_id using `subset', generate(_mergevdem)

drop if _mergevdem==2 
drop _mergevdem

isid coder_id country_id historical_date 

sort country_id coder_id historical_date
egen byte coder_tag = tag(coder_id)
g uniquedate = historical_date + "_" + country

local varlist v2elembaut v2elembcap v2elmulpar v2elrgstry ///
v2elvotbuy v2elirreg v2elintim v2elpeace ///
v2elfrfair v2elrgpwr v2ellocpwr v2elsnlsff ///
v2psbars v2psparban v2psoppaut v2pscnslnl ///
v2exrescon v2exdfcbhs v2exdfdmhs ///
v2exdjcbhg v2exdfdshg ///
v2lgqstexp v2lginvstp v2lgotovst v2lgoppart ///
v2dlreason v2dlcommon v2dlcountr v2dlconslt v2dlengage v2dlencmps v2dlunivl ///
v2juhcind v2juncind ///
v2juhccomp v2jucomp v2cltort v2clkill v2clslavem v2clslavef v2cltrnslw ///
v2clrspct v2clacjstm v2clacjstw v2clacjust v2clsocgrp v2cldiscm v2cldiscw ///
v2clacfree v2clrelig v2clfmove v2cldmovem v2cldmovew v2clprptym v2clprptyw ///
v2cseeorgs v2csreprss v2cscnsult v2csprtcpt v2csgender ///
v2mecenefm v2mecrit v2merange v2meharjrn ///
v2meslfcen v2mebias v2pepwrses v2pepwrsoc v2pepwrgen v2peedueq ////
v2pehealth
di "`varlist'"

eststo clear
foreach var in `varlist'{
reghdfe `var' i.bornin, abs(uniquedate)
reghdfe `var' i.bornin, abs(uniquedate)
eststo _`var'
}

esttab `var' using "Tables/Table2.csv", p varlabels (1.bornin "Coder is a national") cells(b(fmt(%5.3f) star) se(fmt(%5.3f) par) p(fmt(%5.3f))) starlevels(* .10 ** .05 *** .01) replace 
/*summary table is created based on inspection of results in .csv file; full results
are reported in the appendix*/

************************************************************************************************
*Figure 3: The Marginal Effect of Country GDP and Coder Nationality on Democracy Assessments
************************************************************************************************
use "V-Dem-CY-Full+Others-v11.1.dta", clear
keep country_name country_text_id country_id year e_polity2 e_migdppcln e_migdppc
keep if year==2012
tempfile temp
save `temp'

clear
import delimited "Restricted/psq.csv", encoding(ISO-8859-2) 
reshape wide value, i(coder_id) j(name) string
sort coder_id
tempfile psq
save `psq'

clear
import delimited "Restricted/v2zzdemyc.csv", encoding(ISO-8859-2) clear 
merge 1:1 coder_id using `psq'
tab _merge
drop _merge
tempfile merged
save `merged'

clear
import delimited "coder_level_ds_v11.1.csv", encoding(ISO-8859-2)  
keep country_text_id coder_id historical_date country_id v2elfrfair v2jupoatck ///
v2lgoppart v2psbars v2exrescon v2eldonate v2elpubfin v2elembaut v2elembcap v2elmulpar ///
v2elrgstry v2elvotbuy v2elirreg v2elintim v2elpeace v2elboycot v2elfrcamp v2elpdcamp ///
v2elpaidig v2elfrfair v2elaccept v2elasmoff v2elrgpwr v2ellocpwr ///
v2elffelr v2elffelrbin v2elsnlsff v2psbars v2psparban v2psoppaut v2psorgs v2psprbrch ///
v2psprlnks v2psplats v2pscnslnl v2pscohesv v2pscomprg v2psnatpar v2pssunpar v2exrescon ///
v2exbribe v2exembez v2excrptps v2exthftps v2exremhsp v2exdfdshs v2exdfcbhs v2exdfcbhs_rec ///
v2exdfvths v2exdfdmhs v2exdfpphs v2exremhog v2exdjdshg v2exdjcbhg v2exdfdshg v2exdfvthg ///
v2exdfpphg v2regsupgroupssize v2regoppgroupssize v2lgdomchm v2lgqstexp ///
v2lginvstp v2lgotovst v2lgcrrpt v2lgoppart v2lgfunds v2lgdsadlo v2lgdsadlobin ///
v2lglegpup v2lglegplo v2lgcomslo v2lgsrvlo v2lgstafflo v2dlreason v2dlcommon v2dlcountr ///
v2dlconslt v2dlengage v2dlencmps v2dlunivl v2jureform v2jupurge v2jupoatck v2jupack ///
v2juaccnt v2jucorrdc v2juhcind v2juncind v2juhccomp v2jucomp v2jureview v2cltort ///
v2clkill v2clslavem v2clslavef v2cltrnslw v2clrspct v2clacjstm v2clacjstw v2clacjust ///
v2clsocgrp v2clrgunev v2cldiscm v2cldiscw v2clacfree v2clrelig v2clfmove v2cldmovem ///
v2cldmovew v2clstown v2clprptym v2clprptyw v2svdomaut v2svinlaut v2cseeorgs v2csreprss ///
v2cscnsult v2csprtcpt v2csgender v2csantimv v2csrlgrep v2csrlgcon v2mecenefm v2mecenefi ///
v2mecenefibin v2mecrit v2merange v2meharjrn v2meslfcen v2mebias v2mecorrpt ///
v2pepwrses v2pepwrsoc v2pepwrgen v2pepwrort v2peedueq v2pehealth v2peapsecon v2peasjsoecon ///
v2peasbecon v2clgencl v2peapsgen v2peasjgen v2peasbgen v2pepwrgeo v2clgeocl v2peapsgeo ///
v2peasjgeo v2peasbegeo v2clpolcl v2peapspol v2peasjpol v2peasbepol v2peapssoc v2peasjsoc ///
v2peasbsoc v2exl_legitideol v2exl_legitlead v2exl_legitperf ///
v2exl_legitratio v2cacamps v2caviol v2caassemb ///
v2cagenmob v2caconmob v2cademmob v2caautmob v2castate v2catrauni v2capolit v2canonpol ///
v2cafres v2cafexch v2cainsaut v2casurv v2cacritic v2zz*

by coder_id country_id, sort: gen nvals = _n == 1
by coder_id, sort: replace nvals = sum(nvals)
by coder_id, sort: gen nvalsmax = nvals[_N] 
tab nvalsmax
keep if nvalsmax==1
isid coder_id country_id historical_date

gen singlecountrycoder = 1
egen byte coder_tag = tag(coder_id)
keep if coder_tag==1
keep coder_id singlecountrycoder 
tempfile singlecountrycoderids
save `singlecountrycoderids'

use `merged', clear
sort coder_id
merge 1:1 coder_id using `singlecountrycoderids'
keep if _merge==3
drop _merge

replace country_id = 110 if country_id==213
replace country_name = "China" if country_name=="CHINA"

merge m:1 country_id using "vdem_country_codes_regions.dta"
keep if _merge==3
drop _merge

merge m:1 country_name using `temp'

gen bornin=0 if valuev2zzbornin=="FALSE"
replace bornin=1 if valuev2zzbornin=="TRUE"

gen reside=0 if valuev2zzreside=="FALSE"
replace reside=1 if valuev2zzreside=="TRUE"

encode region, generate(region2)
bys country_id: egen byte coder_tot = count(country_id)

bys country_id: egen c = count(coder_id) if bornin==1
bys country_id: egen meanbornin = mean(bornin) 

egen byte country_tag = tag(country_name)

label variable meanbornin "% National Coders"
label variable bornin "Coder Nationality"

label define bornin 0 "Non-national" 1 "National"
label values bornin bornin

label define reside 0 "Non-resident" 1 "Resident"
label values reside reside

sort country_name coder_id
rename code v2zzdemyc

reg v2zzdemyc c.e_migdppcln##i.bornin, vce(robust)
margins bornin, at(e_migdppcln=(6.5 (.5) 12)) 
marginsplot, x(e_migdppcln) graphregion(color(white)) ///
	ytitle("Coder's Democracy Score") title("") ///
	plot1opts(msymbol(circle)) plot2opts(msymbol(diamond))
graph export "Figures/bornin_gdp_margins.png", as(png) replace

****************************************************************************************		
*Figure 4: Trust in Ratings by Rater Nationality
****************************************************************************************
use "authority.dta", clear

mean ratingstrust_1 if intl==1
/*Mean estimation                               Number of obs = 86

----------------------------------------------------------------
               |       Mean   Std. err.     [95% conf. interval]
---------------+------------------------------------------------
ratingstrust_1 |   6.837209   .1818438      6.475655    7.198763
----------------------------------------------------------------*/

mean ratingstrust_2 if intl==1
/*Mean estimation                               Number of obs = 85

----------------------------------------------------------------
               |       Mean   Std. err.     [95% conf. interval]
---------------+------------------------------------------------
ratingstrust_2 |   5.952941   .2014693      5.552297    6.353585
----------------------------------------------------------------*/

mean ratingstrust_3 if intl==1
/*Mean estimation                               Number of obs = 85

----------------------------------------------------------------
               |       Mean   Std. err.     [95% conf. interval]
---------------+------------------------------------------------
ratingstrust_3 |   7.082353   .1667046      6.750843    7.413863
----------------------------------------------------------------*/

mean ratingstrust_1 if intl==0
/*Mean estimation                               Number of obs = 45

----------------------------------------------------------------
               |       Mean   Std. err.     [95% conf. interval]
---------------+------------------------------------------------
ratingstrust_1 |   5.755556   .2791682      5.192929    6.318182
----------------------------------------------------------------*/

mean ratingstrust_2 if intl==0
/*Mean estimation                               Number of obs = 45

----------------------------------------------------------------
               |       Mean   Std. err.     [95% conf. interval]
---------------+------------------------------------------------
ratingstrust_2 |   6.333333   .2620818      5.805142    6.861524
----------------------------------------------------------------*/

mean ratingstrust_3 if intl==0
/*Mean estimation                               Number of obs = 45

----------------------------------------------------------------
               |       Mean   Std. err.     [95% conf. interval]
---------------+------------------------------------------------
ratingstrust_3 |   5.955556   .2619961      5.427537    6.483574
----------------------------------------------------------------*/


/*make figure manually*/
clear
gen authority = .
set obs 1
replace authority = .9 in 1
set obs 2
replace authority = 1 in 2
set obs 3
replace authority = 1.1 in 3
set obs 4
replace authority = 1.9 in 4
set obs 5
replace authority = 2 in 5
set obs 6
replace authority = 2.1 in 6
set obs 7
replace authority = 2.9 in 7
set obs 8
replace authority = 3 in 8
set obs 9
replace authority = 3.1 in 9
set obs 10
label define scorers 3 "Freedom House" 2 "International Experts" 1 "National Experts"
label values authority scorers
gen intl=.
replace intl = 6.837209 if authority>3 & authority<3.5
replace intl = 7.082353 if authority>2 & authority<2.5
replace intl = 5.952941 if authority>1 & authority<1.5
gen intll=.
replace intll = 6.475655 if authority>3 & authority<3.5
replace intll = 6.750843 if authority>2 & authority<2.5
replace intll = 5.552297 if authority>1 & authority<1.5
gen intlu=.
replace intlu = 7.198763 if authority>3 & authority<3.5
replace intlu = 7.413863 if authority>2 & authority<2.5
replace intlu = 6.353585 if authority>1 & authority<1.5
gen natl=.
replace natl = 5.755556 if authority<3 & authority>2.5
replace natl = 5.955556 if authority<2 & authority>1.5
replace natl = 6.333333 if authority<1
gen natll=.
replace natll = 5.192929 if authority<3 & authority>2.5
replace natll = 5.427537 if authority<2 & authority>1.5
replace natll = 5.805142 if authority<1
gen natlu=.
replace natlu = 6.318182 if authority<3 & authority>2.5
replace natlu = 6.483574 if authority<2 & authority>1.5
replace natlu = 6.861524 if authority<1
#delimit ;
twoway (scatter authority intl, msize(medlarge) mcolor(stc2) lcolor(stc2) connect(none) msymbol(circle)) 
(rcap intll intlu authority, horizontal lcolor(stc2) lwidth(thin) )
 (scatter authority natl, msize(medlarge) mcolor(stc1) lcolor(stc1) connect(none) msymbol(diamond)) 
(rcap natll natlu authority, horizontal lcolor(stc1) lwidth(thin) ), 
title("", color(black))
xtitle("Average Trust", size(medlarge))
ytitle("")
xlabel(5 "5.0" 6 "6.0" 7 "7.0" 8 "8.0", valuelabel labsize(medlarge) glcolor(gs10) gmax angle(horizontal))
ylabel(1(1)3, valuelabel labsize(medlarge) nogrid)
legend(order( 1 "International users" 3 "National users" ) size(medlarge))
;
graph export "Figures/authority_assessments.png", as(png) replace
